﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
using Microsoft.Xaml.Behaviors;

namespace Tnelab.Wpf
{
	public partial class WindowEx
	{
		static BlurForWindowBehavior _blurForWindowBehavior = new();
		public static readonly DependencyProperty BlurableProperty =
			DependencyProperty.RegisterAttached("Blurable", typeof(bool), typeof(WindowEx), new(false, OnBlurableChanged));
		static void OnBlurableChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
		{
			var window = obj as Window;
			if (e.NewValue != e.OldValue)
			{
				var value = (bool)e.NewValue;
				if (value)
					Interaction.GetBehaviors(window).Add(_blurForWindowBehavior);
				else
					Interaction.GetBehaviors(window).Remove(_blurForWindowBehavior);
			}
		}
		public static bool GetBlurable(Window dpo)
		{
			return (bool)dpo.GetValue(BlurableProperty);
		}

		public static void SetBlurable(Window dpo, bool value)
		{
			dpo.SetValue(BlurableProperty, value);
		}
	}

}
